<template>
  <div class="app-container">
    <el-form :inline='true' :model="queryParams" label-width="80px">
        <el-form-item label="追溯号" >
              <el-input class="border-input" v-model="queryParams.traceabilityNumber" placeholder="请输入追溯号" value=""></el-input>
        </el-form-item>
         <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery('serach')">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery('serach')">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['fb:preprinting:add']">新增</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="makingList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="记录ID" align="center" prop="recordId" fixed="left" />
      <el-table-column label="机长" align="center" prop="leader" fixed="left" />
      <!-- <el-table-column label="审核人" align="center" prop="auditor" fixed="left" /> -->
      <!-- <el-table-column label="出勤人员（排除机长）" align="center" prop="attendanceInstructionsVo.personnel" fixed="left" /> -->
      <!-- <el-table-column label="出勤人员时间" align="center" prop="attendanceInstructionsVo.personnelTimeH" /> -->
      <!-- <el-table-column label="生产工单ID" align="center" prop="workorderId" /> -->
      <!-- <el-table-column label="出勤人员数量" align="center" prop="attendanceInstructionsVo.personnelNumber" /> -->
      <!-- <el-table-column label="交班情况" align="center" prop="attendanceInstructionsVo.handoverSituation" /> -->
      <!-- <el-table-column label="生产任务ID" align="center" prop="taskId" /> -->
      <el-table-column label="报表号" align="center" prop="reportNo" />
      <!-- <el-table-column label="产品物料ID" align="center" prop="itemId" /> -->
      <el-table-column label="设备名称" align="center" prop="machineryName" />
      <el-table-column label="设备编码" align="center" prop="machineryCode" />
      <el-table-column label="工单" align="center" prop="workorderId" />
      <el-table-column label="工单名称" align="center" prop="workorderName" />
      <el-table-column label="生产任务" align="center" prop="taskId" />
      <el-table-column label="生产任务编号" align="center" prop="taskCode" />
      <el-table-column label="产品编号" align="center" prop="itemCode" />
      <el-table-column label="产品名称" align="center" prop="itemName" />
      <el-table-column label="产品重量" align="center" prop="itemWeight" />
      <el-table-column label="合格数" align="center" prop="quantityQualified" show-overflow-tooltip />
      <el-table-column label="班次" align="center" prop="workGroup" />
      <el-table-column label="客户编码" align="center" prop="clientCode" />
      <el-table-column label="客户名称" align="center" prop="clientName" />
      <el-table-column label="创建时间" align="center" prop="createTime" />
      <el-table-column label="创建人" align="center" prop="createBy" />
      <el-table-column label="更新时间" align="center" prop="updateTime" />
      <el-table-column label="总预印数(张)" align="center" prop="preprintNumberCount" />
      <el-table-column label="总制袋数（个）" align="center" prop="bagNumberCount" />
      <el-table-column label="总料头(KG)" align="center" prop="stubBarCount" />
      <el-table-column label="换料时间" align="center" prop="refuellingTime" />
      <el-table-column label="总返修（次品）" align="center" prop="rejRepairCount" />
      <el-table-column label="总印刷（次品）" align="center" prop="rejPrintCount" />
      <el-table-column label="总其他（次品）" align="center" prop="rejOtherCount" />
      <el-table-column label="总料头(KG)" align="center" prop="scrBlockingCount" />
      <el-table-column label="总堵料(报废)" align="center" prop="stubBarCount" />
      <el-table-column label="总印废(报废)" align="center" prop="scrPrintingWasteCount" />
      <el-table-column label="总废袋数(报废)" align="center" prop="scrBagWasteCount" />
      <el-table-column label="总废袋重(KG)" align="center" prop="bagWasteWeightCount" />
      <el-table-column label="总超料重(KG)" align="center" prop="excessMaterialCount" />
      <el-table-column label="生产日期" align="center" prop="produceTime" />

      <el-table-column label="操作" align="center" width="120" class-name="small-padding fixed-width" fixed="right">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-if="scope.row.fbStatus !== 2" v-hasPermi="['fb:preprinting:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-if="scope.row.fbStatus !== 2" v-hasPermi="['fb:preprinting:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />

    <!-- 添加 -->
    <el-dialog :title="title" :visible.sync="open" :fullscreen="true">
     <el-row>
        <el-col>
          <el-form :model="form" label-width="68px">
           <el-form-item label="追溯号" >
              <el-input v-model="form.traceabilityNumber" placeholder="请输入追溯号" value=""></el-input>
            </el-form-item>
          </el-form>
        </el-col>
     </el-row>
      <el-collapse v-model="activeNames" @change="handleChange">
        <el-collapse-item title="制袋数据" name="1">
          <div class="table-box-body">
            <table width="100%" border="1">
              <tr>
                <td colspan="5">
                  机台号：
                  <el-button @click.native="Infn('device')">选择</el-button>
                  {{ form.machineryId ? `【${form.machineryId}】` : "" }}
                  <!-- <el-select v-model="form.machineryId" placeholder="请选择设备" @click.native="Infn('device')">
                    <el-option v-for="(item, index) in machineryList" :key="index" :label="item.machineryName" :value="item.machineryId"></el-option>
                  </el-select>-->
                </td>
                <td colspan="6">
                  班组：
                  <el-input value v-model="form.workGroup" />
                </td>
                <td colspan="7">
                  生产日期：
                  <el-date-picker @change="handPicker" v-model="form.produceTime" type="date" placeholder="选择日期"></el-date-picker>
                </td>
              </tr>
              <tr>
                <td colspan="5">
                  工作单号:
                  <el-button @click.native="Infn('productSpc')">选择</el-button>
                  {{ form.workorderId ? `【${form.workorderId}】` : "" }}
                </td>
                <td colspan="6">
                  产品编号：
                  <!-- <el-select v-model="form.itemId" clearable filterable placeholder="请选择产品编号" @click.native="Infn('workorder')">
                    <el-option v-for="(item, index) in orderList" :key="index" :label="item.productCode" :value="item.productId"></el-option>
                  </el-select> -->
                   {{ productCode ? `【${productCode}】` : "" }}
                </td>
                <td colspan="7">
                  产品规格：
                   {{ form.productSpc ? `【${form.productSpc}】` : "" }}
                  <!-- <el-select
                    v-model="form.productSpc"
                    clearable
                    placeholder="请选择产品规格"
                    @click.native="Infn('productSpc')"
                  >
                    <el-option
                      v-for="(item, index) in workorderList"
                      :key="index"
                      :label="item.productSpc"
                      :value="item.productSpc"
                    ></el-option>
                  </el-select>-->
                </td>
              </tr>
              <tr>
                <td rowspan="2" colspan="2">预印批号（卷号）</td>
                <td rowspan="2" colspan="2">预印数（张）</td>
                <td rowspan="2" colspan="2">制袋数（个）</td>
                <td rowspan="2">料头（KG）</td>
                <td colspan="3">次品数</td>
                <td colspan="5">报废数</td>
                <td></td>
              </tr>
              <tr>
                <td>返修</td>
                <td>印刷</td>
                <td>其它</td>
                <td>堵料</td>
                <td>印刷废品</td>
                <td>制袋废品</td>
                <td>废袋（kg）</td>
                <td>超料（kg）</td>
                <td></td>
              </tr>
              <tr v-for="(item, index) in form.bagMakingRecordVo" :key="index">
                <td colspan="2">
                  <el-input value v-model="item.rollNumber" />
                </td>
                <td colspan="2">
                  <el-input @change="handNum('prepri')" type='number' :min="0" value v-model.number="item.preprintNumber" />
                </td>
                <td colspan="2">
                  <el-input value @change="handNum('bag')" type='number' :min="0" v-model.number="item.bagNumber" />
                </td>
                <td>
                  <!-- <el-input value @change="handNum('stub')" v-model.number="item.stubBar" /> -->
                  <el-input-number @change="handNum('stub')" type='number' :min="0" value :controls="false" v-model="item.stubBar" :precision="2"></el-input-number>
                </td>
                <td>
                  <el-input value @change="handNum('rejRe')" type='number' :min="0" v-model.number="item.rejRepair" />
                </td>
                <td>
                  <el-input value @change="handNum('rejPr')" type='number' :min="0" v-model.number="item.rejPrint" />
                </td>
                <td>
                  <el-input value @change="handNum('rejOt')" type='number' :min="0" v-model.number="item.rejOther" />
                </td>
                <td>
                  <el-input value @change="handNum('scrBlock')" type='number' :min="0" v-model.number="item.scrBlocking" />
                </td>
                <td>
                  <el-input value @change="handNum('scrPrint')" type='number' :min="0" v-model.number="item.scrPrintingWaste" />
                </td>
                <td>
                  <el-input value @change="handNum('scrBag')" type='number' :min="0" v-model.number="item.scrBagWaste" />
                </td>
                <td>
                  <el-input-number @change="handNum('bagWaste')"  value :controls="false" v-model="item.bagWasteWeight" :precision="2"></el-input-number>
                </td>

                <td>
                  <el-input-number @change="handNum('excess')" value :controls="false" v-model="item.excessMaterial" :precision="2"></el-input-number>
                </td>
                <td>
                  <el-button type="text" @click="handdele(item, 'bagMakin')">删除</el-button>
                </td>
              </tr>
              <tr>
                <td colspan="2">合计：</td>
                <td colspan="2">
                  <el-input value v-model="form.preprintNumberCount" />
                </td>
                <td colspan="2">
                  <el-input value v-model="form.bagNumberCount" />
                </td>
                <td>
                  <el-input value v-model="form.stubBarCount" />
                </td>
                <td>
                  <el-input value v-model="form.rejRepairCount" />
                </td>
                <td>
                  <el-input value v-model="form.rejPrintCount" />
                </td>
                <td>
                  <el-input value v-model="form.rejOtherCount" />
                </td>
                <td>
                  <el-input value v-model="form.scrBlockingCount" />
                </td>
                <td>
                  <el-input value v-model="form.scrPrintingWasteCount" />
                </td>
                <td>
                  <el-input value v-model="form.scrBagWasteCount" />
                </td>
                <td>
                  <el-input value v-model="form.bagWasteWeightCount" />
                </td>
                <td>
                  <el-input value v-model="form.excessMaterialCount" />
                </td>
                <td></td>
              </tr>
            </table>
          </div>
          <div>
            <span slot="footer" class="diafooter">
              <el-button type="primary" @click="handbagMaking('bagMaking')">添加数据</el-button>
            </span>
          </div>
        </el-collapse-item>
        <!-- 停机故障 -->
        <el-collapse-item title="停机故障" name="2">
          <table width="100%" border="1">
            <tr>
              <td colspan="18">停机及故障记录</td>
            </tr>
            <tr>
              <td colspan="3">停机原因</td>
              <td colspan="4">开始时间</td>
              <td colspan="2">结束时间</td>
             <td>时间/M</td>
              <td colspan="2">停机项</td>
              <td colspan="2">处置说明</td>
              <td colspan="2">主管意见</td>
              <td></td>
            </tr>
            <tr v-for="(item, index) in form.shutdownRecordsVo" :key="index">
              <td colspan="3">
                <el-input v-model="item.haltReason" placeholder="请输入停机原因"></el-input>
              </td>
              <td colspan="4">
                <el-date-picker v-model="item.startTime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择开始时间"></el-date-picker>
              </td>
              <td colspan="2">
                <el-date-picker v-model="item.endTime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择结束时间"></el-date-picker>
              </td>
              <td>
                  <el-input-number  value :controls="false" v-model="item.timeH"  :min="0" ></el-input-number>
              </td>
              <td colspan="2">
                <el-select v-model="item.shutdownItems" placeholder="请选择停机类型">
                  <el-option v-for="dict in dict.type.mes_shutdown_type" :key="dict.value" :label="dict.label"
                    :value="dict.value" />
                </el-select>
              </td>
              <td colspan="2">
                <el-input value v-model="item.explain" />
              </td>
              <td colspan="2">
                <el-input value v-model="item.opinion" />
              </td>
              <td>
                <el-button type="text" @click="handdele(item, 'shutdown')">删除</el-button>
              </td>
            </tr>

            <tr>
              <td colspan="2">换料头：</td>
              <td colspan="2">
                <el-input value v-model="gouse[0]" />
              </td>
              <td colspan="2">
                <el-input value v-model="gouse[1]" />
              </td>
              <td>
                <el-input value v-model="gouse[2]" />
              </td>
              <td>
                <el-input value v-model="gouse[3]" />
              </td>
              <td>
                <el-input value v-model="gouse[4]" />
              </td>
              <td>
                <el-input value v-model="gouse[5]" />
              </td>
              <td>
                <el-input value v-model="gouse[6]" />
              </td>
              <td>
                <el-input value v-model="gouse[7]" />
              </td>
              <td>
                <el-input value v-model.number="gouse[8]" />
              </td>
              <td>
                <el-input value v-model.number="gouse[9]" />
              </td>
              <td>
                <el-input value v-model.number="gouse[10]" />
              </td>
            </tr>
          </table>
          <div>
            <span slot="footer" class="diafooter">
              <el-button type="primary" @click="handbagMaking('shutdown')">添加数据</el-button>
            </span>
          </div>

          <div class="fonts">设备故障项:A喷胶头;B分切刀电机;C热熔胶机;D纠偏器;E手挽拉板;F支撑轴;G张力系统;H单向轴承I链条:J输送带:K橡胶压辊:L胶水开关;M轴承;N电器按键:0皮带:P压杆打滑;夹具损R真空泵:S胶水光电:T电器控制:U飞达吸盘;Y其它:W电器:X气路:Y齿轮</div>
          <div class="fonts">非设备故障项:1换规格;2洗胶;3运行微调;4换切刀:5辅料异常:6计划停机;7无人停机;8无单停机9清理机台;10保养;11待料;12换料;13排班;14堵料;15断料;16原料异常;17其他</div>
        </el-collapse-item>

        <!-- 出勤说明 -->
        <el-collapse-item title="出勤说明" name="3">
          <table width="100%" border="1">
            <tr>
              <td colspan="3">类别</td>
              <td colspan="3">开始时间</td>
              <td colspan="3">结束时间</td>
              <td>时间/M</td>
              <td colspan="6">主管意见</td>
              <td></td>
            </tr>
            <tr v-for="(item,index) in form.attendanceInstructionsVo.continuousShift" :key="index"> 
              <td colspan="3">连班</td>
              <td colspan="3">
                <el-time-picker value-format="HH:mm" v-model="
                   item.startTime
                  " placeholder="开始时间"></el-time-picker>
              </td>
              <td colspan="3">
                <el-time-picker value-format="HH:mm" v-model="item.endTime" placeholder="结束时间"></el-time-picker>
              </td>
              <td>
                 <el-input-number  value :controls="false" v-model="item.timeH"  :min="0" ></el-input-number>
              </td>
              <td colspan="6">
                <el-input value v-model="item.opinion" />
              </td>
              <td> <el-button type="text" @click="handdele(item, 'continuou')">删除</el-button></td>
            </tr>

            <tr>
              <td colspan="3">出勤人员</td>
              <td colspan="6">
                <el-tag :key="index" v-for="(item, index) in form.attendanceInstructionsVo.personnel" closable :disable-transitions="false" @close="handleClose(item)">{{ item }}</el-tag>
                <el-button class="button-new-tag" size="small" @click="handCaptain('add')">+ 添加人员</el-button>
              </td>

              <td colspan="3">交班情况</td>
              <td colspan="4">
                <el-input value v-model="form.attendanceInstructionsVo.handoverSituation" />
              </td>
              <td></td>
            </tr>
            <tr>
              <td colspan="3">出勤人员数量</td>
              <td colspan="6">
                <el-input value v-model="form.attendanceInstructionsVo.personnelNumber" />
              </td>

              <td colspan="3">出勤人员时间</td>
              <td colspan="4">
                   <el-input-number  value :controls="false" v-model="form.attendanceInstructionsVo.personnelTimeH"  :min="0" ></el-input-number>
              </td>
              <td></td>
            </tr>
          </table>

          <div>
            <span slot="footer" class="diafooter">
              <el-button type="primary" @click="handbagMaking('itemTime')">添加数据</el-button>
            </span>
          </div>
        </el-collapse-item>
        <!-- 填表信息 -->
        <el-collapse-item title="填表信息" name="4">
          <div class="boxs">
            <el-form ref="form" :model="form" :inline="true" label-width="80px">
              <el-form-item label="填表人：">
                <el-input v-model="form.filledBy"></el-input>
              </el-form-item>
              <el-form-item label="班组：">
                <el-input v-model="form.workGroup"></el-input>
              </el-form-item>
              <el-form-item label="机长：">
                <el-button type="primary" @click="handCaptain('jizhang')">选择机长</el-button>
                {{ form.leader ? `【${form.leader}】` : "" }}
              </el-form-item>
            </el-form>
          </div>
        </el-collapse-item>
      </el-collapse>

      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="sumbit()">提交</el-button>
        <el-button @click="handeDele('bagMaking')">取消</el-button>
      </span>
    </el-dialog>

    <!-- 选择机长 -->
    <el-dialog title="选择机长" :visible.sync="captain" width="50%">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="68px">
        <el-form-item label="账号" prop="userName">
          <el-input v-model="queryParams.userName" placeholder="请输入账号" clearable style="width: 240px" @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <el-table :data="captainList" border style="width: 100%" ref="multipleTable" @selection-change="handleSelectionChange">
        <el-table-column  type="selection"  width="55"></el-table-column>
        <el-table-column prop="userName" label="账号" align="center"></el-table-column>
        <el-table-column prop="nickName" label="姓名" align="center"></el-table-column>
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-button size="mini" type="text" icon="el-icon-edit" @click="handAca(scope.row,'catpan','add')">选择</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getDate" />
      <span slot="footer" class="dialog-footer">
        <el-button @click="captain = false">取 消</el-button>
        <el-button v-if="this.type=='add'" @click="hanBatch">批量选择</el-button>
        <el-button v-else type="primary" @click="captain = false">返 回</el-button>
      </span>
    </el-dialog>

    <!-- 工作单号 -->
    <el-dialog title="选择工作单号" :visible.sync="machine" width="50%">
      <el-table :data="workorderList" border style="width: 100%">
        <el-table-column prop="workorderId" label="工单ID" align="center"></el-table-column>
        <el-table-column prop="workorderName" label="工单名称" align="center"></el-table-column>
        <el-table-column align="center" prop="productCode" label="产品编号"></el-table-column>
        <el-table-column align="center" prop="productSpc" label="产品规格"></el-table-column>
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-button size="mini" type="text" icon="el-icon-edit" @click="handAca(scope.row,'workOrder')">选择</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getDate" />
      <span slot="footer" class="dialog-footer">
        <el-button @click="machine = false">取 消</el-button>
        <el-button type="primary" @click="machine = false">返 回</el-button>
      </span>
    </el-dialog>

    <!-- 机台号 -->
    <el-dialog title="选择机台号" :visible.sync="workorder" width="50%">
      <el-table :data="machineryList" border style="width: 100%">
        <el-table-column prop="machineryId" label="机台ID" align="center"></el-table-column>
        <el-table-column prop="machineryName" label="机台名称" align="center"></el-table-column>
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-button size="mini" type="text" icon="el-icon-edit" @click="handAca(scope.row,'machine')">选择</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getDate" />
      <span slot="footer" class="dialog-footer">
        <el-button @click="workorder = false">取 消</el-button>
        <el-button type="primary" @click="workorder = false">返回</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {
  addMaking,
  MakiDelete,
  MakingList,
  editMaking,
  EditMaking
} from "@/api/mes/fb/making";
import { listUser } from "@/api/system/user";
import { listMachinery } from "@/api/mes/dv/machinery";
import { listOrder } from "@/api/mes/md/order";
import { listWorkorder } from "@/api/mes/pro/workorder";
export default {
  name: "Preprinting",
  dicts: ["mes_fb_status", "mes_shutdown_type"],

  data() {
    return {
      // 弹出层标题
      title: "",
      titles: "",
      // 是否显示弹出层
      open: false,
      value: "",
      value1: null,
      loading: true,
      workorder: false,
      captain: false, //选择机长
      machine: false, //机台号
      makingList: [], //列表数据
      machineryList: [], //设备列表
      orderList: [], //订单列表
      workorderList: [], //生产工单（产品规格）
      activeNames: ["1"],
      inputVisible: false,
      captainList: [],
      inputValue: "",
      // 总条数
      total: 0,
      productCode:'',
      type:'',
      // 表单参数
      form: {
        leader: "",
        traceabilityNumber:null,
        itemId: null,
        bagMakingRecordVo: [
          {
            rollNumber: "",
            preprintNumber: 0,
            bagNumber: 0,
            stubBar: 0,
            rejRepair: 0,
            rejPrint: 0,
            rejOther: 0,
            scrBlocking: 0,
            scrPrintingWaste: 0,
            scrBagWaste: 0,
            bagWasteWeight: 0,
            excessMaterial: 0.0,
          },
        ],
        shutdownRecordsVo: [
          {
            haltReason: "",
            startTime: "",
            endTime: "",
            timeH: "",
            shutdownItems: "",
            explain: "",
            opinion: "",
          },
        ],
        attendanceInstructionsVo: {
          continuousShift: [{
            startTime: "",
            endTime: "",
            timeH: "",
            opinion: "",
          }],
          personnel: [],
          personnelTimeH: "",
          personnelNumber: null,
          handoverSituation: "",
        },
        reportNo: null,
        machineryId: null,
        workorderId: null,
        taskId: null,
        workGroup: null,
        fbStatus: null,
        filledBy: null,
        preprintNumberCount: 0,
        bagNumberCount: 0,
        stubBarCount: 0,
        refuellingTime: null,
        rejRepairCount: 0,
        rejPrintCount: 0,
        rejOtherCount: 0,
        scrBlockingCount: 0,
        scrPrintingWasteCount: 0,
        scrBagWasteCount: 0,
        bagWasteWeightCount: 0,
        excessMaterialCount: 0,
        produceTime: null,
      },
      gouse: [],
      ids: null,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    // 初始化
    getList() {
      this.loading = true;
      MakingList(this.queryParams).then((res) => {
        this.makingList = res.rows;
        this.total = res.total;
        this.loading = false;
      });
    },
    // 触发设备监听事件
    Infn(data) {
      if (data == "device") {
        listMachinery(this.queryParams).then((res) => {
          this.machineryList = res.rows;
          this.total = res.total;
          this.workorder = true;
        });
        return;
      }
      if (data == "workorder") {
        listOrder(this.queryParams).then((res) => {
          const map = new Map();
          this.orderList = res.rows.filter(
            (v) => !map.has(v.productCode) && map.set(v.productCode, v)
          );
          console.log(this.orderList, "orderlist");
        });
        return;
      }
      if (data == "productSpc") {
        listWorkorder(this.queryParams).then((res) => {
          this.workorderList = res.rows;
          this.total = res.total;
          this.machine = true;
        });
        return;
      }
    },
    reset(){
      this.form={
        leader: "",
        itemId: null,
        traceabilityNumber:null,
        bagMakingRecordVo: [
          {
            rollNumber: "",
            preprintNumber: 0,
            bagNumber: 0,
            stubBar: 0,
            rejRepair: 0,
            rejPrint: 0,
            rejOther: 0,
            scrBlocking: 0,
            scrPrintingWaste: 0,
            scrBagWaste: 0,
            bagWasteWeight: 0,
            excessMaterial: 0.0,
          },
        ],
        shutdownRecordsVo: [
          {
            haltReason: "",
            startTime: "",
            endTime: "",
            timeH: "",
            shutdownItems: "",
            explain: "",
            opinion: "",
          },
        ],
        attendanceInstructionsVo: {
          continuousShift: [{
            startTime: "",
            endTime: "",
            timeH: "",
            opinion: "",
          }],
          personnel: [],
          personnelTimeH: "",
          personnelNumber: null,
          handoverSituation: "",
        },
        reportNo: null,
        machineryId: null,
        workorderId: null,
        taskId: null,
        workGroup: null,
        fbStatus: null,
        filledBy: null,
        preprintNumberCount: 0,
        bagNumberCount: 0,
        stubBarCount: 0,
        refuellingTime: null,
        rejRepairCount: 0,
        rejPrintCount: 0,
        rejOtherCount: 0,
        scrBlockingCount: 0,
        scrPrintingWasteCount: 0,
        scrBagWasteCount: 0,
        bagWasteWeightCount: 0,
        excessMaterialCount: 0,
        produceTime: null,
      }
      this.productCode=''
      this.gouse=[]
    },
    // 选择机长
    handAca(row, index) {
      if (index == "catpan") {
        if(this.type=='add'){
          this.form.attendanceInstructionsVo.personnel.push(row.nickName)
          this.captain = false;
          return;
        }else{
           this.form.leader = row.nickName;
            this.captain = false;
          return;
        }
      }
      if (index == "workOrder") {
        this.form.workorderId = row.workorderId;
        this.form.itemId = row.productId;
        this.productCode=row.productCode;
        this.form.productSpc = row.productSpc;
        this.machine = false;
        return;
      }
      if (index == "machine") {
        this.form.machineryId = row.machineryId;
        this.workorder = false;
        return;
      }
    },
    handeDele(){
      this.reset(),
      this.open = false;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.open = true;
      this.title = "添加制袋生产日报";
      this.reset()
    },
    // 添加数据
    sumbit() {
      if(!this.form.leader){
        this.$message.error('请填写机长名称')
        return
      }
      if(!this.form.filledBy){
        this.$message.error('请填写填表人')
        return
      }
      if(this.form.clientId){
        this.form.refuellingTime = this.gouse.join();
          EditMaking(this.form).then(res=>{
          this.reset()
          this.$modal.msgSuccess("编辑成功");
            this.getList()
          this.open = false;
          })
      }else{
        this.form.refuellingTime = this.gouse.join();
        addMaking(this.form).then((res) => {
          this.$modal.msgSuccess("添加成功");
          this.reset()
          this.getList()
          this.open = false;
        });
      }
    },
    // 查看数据
    handleUpdate(row) {
      this.title = "查看制袋生产日报详情";
      editMaking(row.recordId).then((res) => {
        this.form=res.data
        let _data=JSON.parse(this.form.shutdownrecords)
        this.form.attendanceInstructionsVo=JSON.parse(this.form.attendanceinstructions)
        this.form.bagMakingRecordVo=JSON.parse(this.form.bagmakingrecord)
        this.productCode=this.form.itemCode
        this.gouse=this.form.refuellingTime.split(',').map(Number);
        this.form.shutdownRecordsVo=this.form.shutdownRecordsVo.map(item=>({
          startTime:item.shutdownTime,
          endTime:item.resumptionTime,
          timeH:item.affectDuration,
          haltReason:item.shutdownContent,
          shutdownItems:item.shutdownType,
          recordId:item.recordId,
          opinion:item.attr1,
          explain:item.remark
        }))
        this.open = true;
        this.title='修改制袋生产日报'
      });
    },
    // 删除数据
    handleDelete(row) {
      const recordIds = row.recordId || this.ids;
      this.$modal
        .confirm('是否确认删除生产日报编号为"' + recordIds + '"的数据项？')
        .then(function () {
          return MakiDelete(recordIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    handleChange(val) {
      console.log(val);
    },
    handleQuery(data) {
      if(data=='serach'){
        this.queryParams.pageNum = 1;
        this.getList()
      }else{
         this.queryParams.pageNum = 1;
          this.getDate();
      }
    },
    resetQuery(data) {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
      };
      if(data=='serach'){
        this.getList()
      }else{
        this.getDate();
      }
    },
    // 多选框
    handleSelectionChange(val) {
      console.log(val);
    },
    // 批量选择
    hanBatch(){
      this.form.attendanceInstructionsVo.personnel=this.$refs.multipleTable.selection.map(v=>v.nickName)
      this.captain=false;
      this.type='';
    },
    handCaptain(data) {
      if(data=='add'){
        this.type='add'
      }else if(data=='jizhang'){
        this.type=''
      }
      this.getDate();
      this.captain = true;
    },
    // 添加数据
    handbagMaking(data) {
      if (data == "bagMaking") {
        this.form.bagMakingRecordVo.push({
          rollNumber: null,
          preprintNumber: 0,
          bagNumber: 0,
          stubBar: 0,
          rejRepair: 0,
          rejPrint: 0,
          rejOther: 0,
          scrBlocking: 0,
          scrPrintingWaste: 0,
          scrBagWaste: 0,
          bagWasteWeight: 0,
          excessMaterial: 0,
        });
      } else if (data == "shutdown") {
        this.form.shutdownRecordsVo.push({
          haltReason: "",
          startTime: "",
          endTime: "",
          timeH: "",
          shutdownItems: "",
          explain: "",
          opinion: "",
        });
      }else if(data=='itemTime'){
         this.form.attendanceInstructionsVo.continuousShift.push({
            startTime: "",
            endTime: "",
            timeH: "",
            opinion: "",
        });
      }
    },
    getDate() {
      listUser(this.queryParams).then((res) => {
        this.captainList = res.rows;
        this.total = res.total;
      });
    },

    // 删除人名
    handleClose(tag) {
      this.form.attendanceInstructionsVo.personnel.splice(
        this.form.attendanceInstructionsVo.personnel.indexOf(tag),
        1
      );
    },

    // 删除单条数据
    handdele(data, index) {
      if (index == "bagMakin") {
        this.form.bagMakingRecordVo.splice(
          this.form.bagMakingRecordVo.indexOf(data),
          1
        );
        this.form.preprintNumberCount =
          this.form.preprintNumberCount - data.preprintNumber;
        this.form.bagNumberCount = this.form.bagNumberCount - data.bagNumber;
        this.form.stubBarCount = this.form.stubBarCount - data.stubBar;
        this.form.rejRepairCount = this.form.rejRepairCount - data.rejRepair;
        this.form.rejPrintCount = this.form.rejPrintCount - data.rejPrint;
        this.form.rejOtherCount = this.form.rejOtherCount - data.rejOther;
        this.form.scrBlockingCount =
          this.form.scrBlockingCount - data.scrBlocking;
        this.form.scrPrintingWasteCount =
          this.form.scrPrintingWasteCount - data.scrPrintingWaste;
        this.form.scrBagWasteCount =
          this.form.scrBagWasteCount - data.scrBagWaste;
        this.form.bagWasteWeightCount =
          this.form.bagWasteWeightCount - data.bagWasteWeight;
        this.form.excessMaterialCount =
          this.form.excessMaterialCount - data.excessMaterial;
      } else if (index == "shutdown") {
        this.form.shutdownRecordsVo.splice(
          this.form.shutdownRecordsVo.indexOf(data),
          1
        );
      }else if(index=='continuou'){
         this.form.attendanceInstructionsVo.continuousShift.splice(
          this.form.attendanceInstructionsVo.continuousShift.indexOf(data),
          1
        );
      }
    },

    handleInputConfirm() {
      let inputValue = this.inputValue;
      if (inputValue) {
        this.form.attendanceInstructionsVo.personnel.push(inputValue);
      }
      this.inputVisible = false;
      this.inputValue = "";
    },

    // 计算总数
    handNum(data) {
      if (data == "prepri") {
        this.form.preprintNumberCount = this.form.bagMakingRecordVo.reduce(
          (sum, e) => sum + Number(e.preprintNumber || 0),
          0
        );
        return;
      }
      if (data == "bag") {
        this.form.bagNumberCount = this.form.bagMakingRecordVo.reduce(
          (sum, e) => sum + Number(e.bagNumber || 0),
          0
        );
        return;
      }
      if (data == "stub") {
        this.form.stubBarCount = this.form.bagMakingRecordVo.reduce(
          (sum, e) => sum + Number(e.stubBar || 0),
          0
        );
        return;
      }
      if (data == "rejRe") {
        this.form.rejRepairCount = this.form.bagMakingRecordVo.reduce(
          (sum, e) => sum + Number(e.rejRepair || 0),
          0
        );
        return;
      }
      if (data == "rejPr") {
        this.form.rejPrintCount = this.form.bagMakingRecordVo.reduce(
          (sum, e) => sum + Number(e.rejPrint || 0),
          0
        );
        return;
      }
      if (data == "rejOt") {
        this.form.rejOtherCount = this.form.bagMakingRecordVo.reduce(
          (sum, e) => sum + Number(e.rejOther || 0),
          0
        );
        return;
      }
      if (data == "scrBlock") {
        this.form.scrBlockingCount = this.form.bagMakingRecordVo.reduce(
          (sum, e) => sum + Number(e.scrBlocking || 0),
          0
        );
        return;
      }
      if (data == "scrPrint") {
        this.form.scrPrintingWasteCount = this.form.bagMakingRecordVo.reduce(
          (sum, e) => sum + Number(e.scrPrintingWaste || 0),
          0
        );
        return;
      }
      if (data == "scrBag") {
        this.form.scrBagWasteCount = this.form.bagMakingRecordVo.reduce(
          (sum, e) => sum + Number(e.scrBagWaste || 0),
          0
        );
        return;
      }
      if (data == "bagWaste") {
        this.form.bagWasteWeightCount = this.form.bagMakingRecordVo.reduce(
          (sum, e) => sum + Number(e.bagWasteWeight || 0),
          0
        );
        return;
      }
      if (data == "excess") {
        this.form.excessMaterialCount = this.form.bagMakingRecordVo.reduce(
          (sum, e) => sum + Number(e.excessMaterial || 0),
          0
        );
        return;
      }
    },
    // 时间进行转换
    handPicker(val) {
      this.form.produceTime = this.transformTime(val);
    },

    // 转日期
    transformTime(d) {
      var date = new Date(d);
      var YY = date.getFullYear() + "-";
      var MM =
        (date.getMonth() + 1 < 10
          ? "0" + (date.getMonth() + 1)
          : date.getMonth() + 1) + "-";
      var DD = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
      return YY + MM + DD;
    },

    forms(data){
      var  timdedetail= data;//假如是10位毫秒需要乘1000
      //获取年份
      var year=new Date(timdedetail).getFullYear();
      //获取月份，获取的月份比实际小1，所以在使用的时候需要+1
      var month=new Date(timdedetail).getMonth()+1 <10?'0'+new Date(timdedetail).getMonth():new Date(timdedetail).getMonth()+1;
      //获取日
      var date=new Date(timdedetail).getDate()<10?'0'+new Date(timdedetail).getDate():new Date(timdedetail).getDate();
      //获取时
      var hours=new Date(timdedetail).getHours()<10?'0'+new Date(timdedetail).getHours():new Date(timdedetail).getHours();
      //获取分
      var minutes=new Date(timdedetail).getMinutes()<10?'0'+new Date(timdedetail).getMinutes():new Date(timdedetail).getMinutes();
      //获取秒
      var seconds=new Date(timdedetail).getSeconds()<10?'0'+new Date(timdedetail).getSeconds():new Date(timdedetail).getSeconds();
      //组合格式为年-月-日 时：分：秒（2021-7-5 21:21:21）
      var time=year+"-"+month+"-"+date+" "+hours+":"+minutes+":"+seconds;
      return time
    }
  },
};
</script>

<style lang="scss" scoped>
table {
  border-collapse: collapse;
}

table td {
  padding: 5px;
  text-align: center;
  font-size: 14px;
  height: 30px;
}

table td em {
  font-style: normal;
  font-size: 16px;
}

table td i {
  font-style: normal;
  font-size: 12px;
}

.table-title {
  margin-bottom: 10px;
}

.table-title span {
  font-weight: bold;
}
.td-80 {
  width: 80px;
}

.td-300 {
  width: 300px;
}
.tips-day-list {
  padding: 10px 0 20px;
  text-align: center;
}
.td-160 {
  width: 160px;
}
.td-240 {
  width: 240px;
}

::v-deep .el-input {
  width: 80%;
}
.diafooter {
  display: flex;
  align-items: flex-end;
  flex-direction: row-reverse;
  margin-top: 20px;
}
.diafooter .el-button {
  margin-left: 10px;
}

::v-deep.el-input--medium .el-input__inner {
  border: 0;
}

.el-tag + .el-tag {
  margin-left: 10px;
}
.button-new-tag {
  margin-left: 10px;
  height: 32px;
  line-height: 30px;
  padding-top: 0;
  padding-bottom: 0;
}
.input-new-tag {
  width: 90px;
  margin-left: 10px;
  vertical-align: bottom;
}
.fonts {
  padding: 0 100px;
  text-align: center;
}

::v-deep.border-input >.el-input__inner{
  border: 1px solid #DCDFE6!important;
}
</style>
